package com.lms.logisticsmanagementsystem.service.Impl;

import com.lms.logisticsmanagementsystem.mapper.CustomerMapper;
import com.lms.logisticsmanagementsystem.model.Customer;
import com.lms.logisticsmanagementsystem.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService{
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public boolean addCustomerInfo(Customer customer) {
        //导入数据，导入成功返回1
        Integer flag = customerMapper.addCustomerInfo(customer);
        if (flag==1){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<Customer> getCustomerInfo() {
        List<Customer> customerList = customerMapper.getCustomerInfo();
        for (Customer customer:customerList){
            if (customer.getSex().equals("1")){
                customer.setSex("男");
            }
            else {
                customer.setSex("女");
            }
        }
        return customerList;
    }

    @Override
    public Customer getCustomerInfoById(Integer id) {
        Customer customer = customerMapper.getCustomerInfoById(id);
        return customer;
    }

    @Override
    public boolean submitEditedCustomerInfo(Customer customer) {
        Integer flag = customerMapper.submitEditedCustomerInfo(customer);
        if (flag==1){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean delCustomerInfoById(Integer id) {
        Integer flag = customerMapper.delCustomerInfoById(id);
        if (flag==1){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public String getCustomerNameById(String cusPhone) {
        String name = customerMapper.getCustomerNameById(cusPhone);
        return name;
    }
}
